package com.clt.ess.gjzw;


import com.clt.ess.utils.HttpUtils;
import org.bouncycastle.util.encoders.Hex;

import java.util.HashMap;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

public class TestGetSecret {

    public static void main(String[] args) {

        String appKey = "e3aec9e4-3b43-427f-ae5e-4a4e4721d65b";
        //租户账号
        String tenantCode = "D62U110ZH001";
        //租户密码
        String password = "62110001";
        String secret = tenantCode + "#" + appKey + "#" + password;

        byte[] md = new byte[32];
        byte[] psw = secret.getBytes();
//            SM3Digest sm3 = new SM3Digest();
        SM3Utils sm3Utils = new SM3Utils();
        sm3Utils.update(psw, 0, psw.length);
        sm3Utils.doFinal(md, 0);
        String sm3Sign = new String(Hex.encode(md));

        Map<String, String> params = new HashMap<>();
        params.put("appkey", appKey);
        params.put("username", tenantCode);
        params.put("sign", sm3Sign);

//                59.255.22.72:8081
        String ss = HttpUtils.post("http://59.255.22.72:8080/aic/rest/service/safety/refreshsecret", params);
//                System.err.println(ss);

        JSONObject aa = JSON.parseObject(ss);

        String aesDncode = SymmetricEncoder.AESDncode(appKey, aa.getString("data"));

        System.out.println(aesDncode);
//        return aesDncode;
    }


}
